function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;
  
  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
	param_name = params[i].substring(0,params[i].indexOf('='));
	if (param_name == parameter) {
		param_value = params[i].substring(params[i].indexOf('=')+1)
	}
  }
  if (param_value) {
	return param_value;
  }
  else {
	return false; 
  }
}

var pid = queryString('pid'); // thay thế bằng tên param của product ID nếu khác
var eventid = queryString('eventid'); // thay thế bằng tên param của event ID nếu khác
var bannerid = queryString('bannerid'); // thay thế bằng tên param của banner ID nếu khác
var notTrackId = new Array("typeRegTopbar","typeDownload","guideReg","textReg","guideDownload","textDownload","typeReg","typePlayNow","typePromotion01","typePromotion02");
var notTrackLink = new Array("http://pay.zing.vn","https://pay.zing.vn","https://hotro1.zing.vn","http://hotro1.zing.vn");
var link_flash ="";
var link = "";
//var urlChoingay ="http://idgunny.zing.vn";
if (pid != false) {
	link_flash += 'pid='+pid;
	if (eventid!=false) {
		  link_flash+='%26eventid='+eventid;
	}
	if (bannerid!=false) {
		  link_flash +='%26bannerid='+bannerid;
	}
} 
function trackLink() {
	setTimeout(function(){
		
		
		if (pid!=false && eventid !=false && bannerid!=false){
				//urlChoingay="https://app.zing.vn/UserClick/MainSite.php?type=152&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;

				if(guideReg && guideReg!=""){
					var urlGuideReg = "https://app.zing.vn/UserClick/MainSite.php?type="+guideReg +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#guideReg").attr("href", urlGuideReg);;

				}
				if(textReg && textReg!=""){
					var urlTextReg = "https://app.zing.vn/UserClick/MainSite.php?type="+textReg +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#textReg").attr("href", urlTextReg);;

				}
				if(guideDownload && guideDownload!=""){
					var urlGuideDownload = "https://app.zing.vn/UserClick/MainSite.php?type="+guideDownload +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#guideDownload").attr("href", urlGuideDownload);;

				}
				if(textDownload && textDownload!=""){
					var urlTextDownload = "https://app.zing.vn/UserClick/MainSite.php?type="+textDownload +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#textDownload").attr("href", urlTextDownload);;

				}
				if(typeReg && typeReg!= "") {
					var urlReg="https://app.zing.vn/UserClick/MainSite.php?type="+typeReg +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#typeReg").attr("href", urlReg);
				}
				if(typeDownload && typeDownload!= "") {
					var urlDownload="https://app.zing.vn/UserClick/MainSite.php?type="+typeDownload +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#typeDownload").attr("href", urlDownload);
				}
				
				if(typePromotion01 && typePromotion01 !=""){
					var urlPromotion01="https://app.zing.vn/UserClick/MainSite.php?type="+typePromotion01 +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#typePromotion01").attr("href", urlPromotion01);
				}
				
				if(typePromotion02 && typePromotion02!=""){
					var urlPromotion02="https://app.zing.vn/UserClick/MainSite.php?type="+typePromotion02 +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#typePromotion02").attr("href", urlPromotion02);
				}
				if(typeRegTopbar && typeRegTopbar!=""){
					var urlRegTopbar="https://app.zing.vn/UserClick/MainSite.php?type="+typeRegTopbar +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
					jQuery("#typeRegTopbar").attr("href", urlRegTopbar);
				}
				if(typePlayNow && typePlayNow!=""){
					try{
						var urlPlayNow =/* urlChoingay + */"https://app.zing.vn/UserClick/MainSite.php?type=" + typePlayNow +"&eventid="+eventid+"&pid="+pid+"&bannerid="+bannerid;
						jQuery("#typePlayNow").attr("href", urlPlayNow);
					} catch(exp){};
				}
				
			
			link='pid='+ pid + '&eventid='+ eventid + '&bannerid=' + bannerid;
			
	
	
		} 
		
		jQuery("a").not(".notTrack").each(function (index) { // use class "notTrack" for untracking a
			if(jQuery.inArray(jQuery(this).attr("id"), notTrackId) == -1){
				var lnk = jQuery(this);
				var href = lnk.attr("href");
				for (k in notTrackLink){
					if(!isNaN(k)){
						var pattstr = "^"+notTrackLink[k];
						var pattLink = new RegExp(pattstr,"i");
						if(pattLink.test(href)){
							return true;
						}
					}
				}
				if (href &&  href.charAt(0)!= "#" && link != ''){
					lnk.attr("href", href + (href.indexOf("?") != -1 ? '&' : '?') + link);
				}
			}
		});
	},10);
}